package com.suredy.app.software.srv;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;

import com.suredy.app.software.model.Software;
import com.suredy.core.service.BaseSrvWithEntity;

@Service
public class SoftwareSrv extends BaseSrvWithEntity<Software> {

	public SoftwareSrv() {
		this.addAnDefOrder("name", true);
		this.addAnDefOrder("upTime", false);
	}

	@Override
	public DetachedCriteria getDc(Software t) {
		DetachedCriteria dc = super.getDc(t);

		if (t == null)
			return dc;

		if (!StringUtils.isBlank(t.getName())) {
			dc.add(Restrictions.like("name", t.getName(), MatchMode.ANYWHERE));
		}

		return dc;
	}

}
